package com.example.actearly_revised;

import com.example.actearly_revised.R;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import android.content.Intent;
import android.graphics.Typeface;

public class OptinScreen extends Activity {

	Button yesButton;
	Button noButton;
	SQLogic entry = new SQLogic(OptinScreen.this);
	Intent p_logic;
	int profile_number;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_optin_screen);
		yesButton = (Button) findViewById(R.id.yesButton);
		noButton = (Button) findViewById(R.id.noButton);
		getActionBar().setTitle("Notification Opt-in");

		LinearLayout pageLayout=(LinearLayout)findViewById(R.id.optinLayout);
		//pageLayout.setBackgroundResource(R.drawable.background);
		//font change
		Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/futuram.ttf");
		TextView Text = (TextView) findViewById(R.id.optinText);
		TextView yesText = (TextView) findViewById(R.id.yesButton);
		TextView noText = (TextView) findViewById(R.id.noButton);

		Text.setTypeface(customFont);
		yesText.setTypeface(customFont);
		noText.setTypeface(customFont);



		p_logic = getIntent();
		profile_number = p_logic.getIntExtra("profile_number",1);

		entry.open();
		User currUser= entry.getUserData(profile_number);
		entry.close();

		TextView optText = (TextView) findViewById(R.id.optinText);
		optText.setText(currUser.getChildname()+ " is " + currUser.getAge(currUser.getBirthdate()) +
				" As " + currUser.getChildname() + " gets older it is important to continue track " + currUser.getChildname() +
				"\'s milestone progress. " + "Would you like to receive notification reminders to do this? ");
		Log.d("stuff", "stuff");
		System.out.println(currUser.getAge(currUser.getBirthdate()));

		yesButton.setOnClickListener(new View.OnClickListener() { // clicked yes

			public void onClick(View v) {
				entry.open();
				entry.UpdateOptIn(profile_number,1); // userId followed by yes/no key
				entry.close();
				finish();
				Intent intent = new Intent("com.example.actearly_revised.PreTracker");
				intent.putExtra("profile_number", profile_number);
				startActivity(intent); // we'll edit this part when we have more sceens

			}
		});

		noButton.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				entry.open();
				entry.UpdateOptIn(profile_number,2);
				entry.close();
				finish();
				Intent intent = new Intent("com.example.actearly_revised.PreTracker");
				intent.putExtra("profile_number", profile_number);
				startActivity(intent); // we'll edit this part when we have more sceens

			}
		});

	}

	/*	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_login_view, menu);
		return true;
	}  */
}
